<template>
    <section>
        <el-col :span="24">
            <el-form inline>
                <el-form-item>
                    <el-input size="small" v-model.trim="form.processing_code" placeholder="加工单" style="width: 150px;" clearable></el-input>
                </el-form-item>
                <el-form-item>
                    <el-input size="small" v-model.trim="form.type_no" placeholder="款号" style="width: 150px;" clearable></el-input>
                </el-form-item>
                <el-form-item>
                    <el-input size="small" v-model.trim="form.factory_contract_no" placeholder="合同编号" style="width: 215px;" clearable></el-input>
                </el-form-item>
                <el-form-item>
                    <el-select v-model="form.supplier_id" filterable remote placeholder="输入搜索的工厂名称" size="small"
                               :remote-method="searchFactoryBtn" :loading="searchLoading" clearable :disabled="user.source_from=='gc'">
                        <el-option v-for="(item,index) in factoryList" :label="item.factory_name" :value="item.supplier_id" :key="index" ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-select size="small" placeholder="扣款状态" v-model="form.k_status" style="width: 120px" clearable>
                        <el-option :value=0 label="未抵扣"></el-option>
                        <el-option :value=2 label="已抵扣"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-select size="small" placeholder="审核状态" v-model="form.status" style="width: 120px" clearable>
                        <el-option :value=0 label="审核中"></el-option>
                        <el-option :value=1 label="已通过"></el-option>
                        <el-option :value=2 label="已拒绝"></el-option>
                        <el-option :value=3 label="已撤回"></el-option>
                        <el-option :value=4 label="已撤销"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" class="el-icon-search" @click="searchBtn" size="small" :loading="btnLoading">查询</el-button>
                </el-form-item>
            </el-form>
        </el-col>
        <el-col :span="24">
            <el-table :data="data" style="width: 100%" :max-height="tableHeight" v-loading="loading" size="mini">
                <el-table-column label="工厂" prop="factory_name" width="120" show-overflow-tooltip></el-table-column>
                <el-table-column label="合同编号" prop="factory_contract_no" width="170"></el-table-column>
                <el-table-column label="加工单" prop="processing_code" width="120"></el-table-column>
                <el-table-column label="款号" prop="type_no" width="100"></el-table-column>
                <el-table-column label="品名" prop="type_name" show-overflow-tooltip></el-table-column>
                <el-table-column label="用途" prop="purpose" show-overflow-tooltip></el-table-column>
                <el-table-column label="单价" prop="price" width="80"></el-table-column>
                <el-table-column label="数量" prop="num" width="60"></el-table-column>
                <el-table-column label="税率(%)" prop="tax_rate" width="70"></el-table-column>
                <el-table-column label="总价" prop="amount" width="80"></el-table-column>
                <el-table-column label="图片" prop="img" width="50">
                    <template slot-scope="{ row }">
                        <el-image v-if="row.images.length>0" :src="row.images[0]" fit="contain" :preview-src-list="row.images">
                            <div slot="error" class="image-slot">
                                <svg t="1718681716906" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2623" width="20" height="20"><path d="M400.696 268.795c-17.249 0-31.233 13.986-31.233 31.233v30.471c0 17.249 13.986 31.233 31.233 31.233s31.233-13.986 31.233-31.233v-30.471c0-17.249-13.985-31.233-31.233-31.233z" fill="#999999" p-id="2624"></path><path d="M623.649 361.734c17.249 0 31.234-13.986 31.234-31.233v-30.471c0-17.249-13.986-31.233-31.234-31.233s-31.233 13.986-31.233 31.233v30.471c-0.001 17.248 13.985 31.233 31.233 31.233z" fill="#999999" p-id="2625"></path><path d="M438.295 388.804c-14.656 9.104-19.155 28.362-10.050 43.013 11.209 18.047 41.976 48.59 86.157 48.59 43.958 0 75.1-30.313 86.574-48.223 9.303-14.529 5.068-33.847-9.455-43.15-14.539-9.298-33.852-5.068-43.15 9.455-0.122 0.199-13.38 19.45-33.969 19.45-20.009 0-32.444-18.128-33.278-19.373-9.166-14.423-28.28-18.805-42.829-9.761z" fill="#999999" p-id="2626"></path><path d="M824.508503 116.690676 571.592236 116.690676c-17.248849 0-31.233352 13.985526-31.233352 31.233352s13.985526 31.233352 31.233352 31.233352l252.916267 0c40.181141 0 72.878844 32.692586 72.878844 72.878844l0 396.966057-189.334159-165.29465c-12.20088-10.655687-30.517037-10.207479-42.173518 0.9967L468.578048 674.16231 309.521472 517.519714c-11.895935-11.70253-30.903847-12.002358-43.154869-0.645706L126.957507 646.163629l0-394.126382c0-40.186258 32.692586-72.878844 72.878844-72.878844l252.916267 0c17.248849 0 31.233352-13.985526 31.233352-31.233352S470.000444 116.690676 452.751594 116.690676L199.836351 116.690676c-74.632791 0-135.346571 60.71378-135.346571 135.346571l0 520.56405c0 74.632791 60.71378 135.346571 135.346571 135.346571l252.916267 0c17.248849 0 31.233352-13.985526 31.233352-31.233352s-13.985526-31.233352-31.233352-31.233352L199.836351 845.481164c-40.186258 0-72.878844-32.692586-72.878844-72.878844l0-41.23924 160.003134-148.385539 159.428036 157.007917c12.048407 11.865235 31.361265 11.981892 43.546795 0.274246l198.576661-190.68697 208.876238 182.346001 0 40.683585c0 40.186258-32.697703 72.878844-72.878844 72.878844L571.592236 845.481164c-17.248849 0-31.233352 13.985526-31.233352 31.233352s13.985526 31.233352 31.233352 31.233352l252.916267 0c74.627674 0 135.346571-60.71378 135.346571-135.346571L959.855074 252.037247C959.855074 177.404456 899.136178 116.690676 824.508503 116.690676z" fill="#999999" p-id="2627"></path></svg>
                            </div>
                        </el-image>
                    </template>
                </el-table-column>
                <el-table-column label="备注" prop="remarks" width="150" show-overflow-tooltip></el-table-column>
                <el-table-column label="创建人" prop="adduser" width="80"></el-table-column>
                <el-table-column label="创建时间" prop="createtime" width="135"></el-table-column>
                <el-table-column label="扣款状态" align="center" prop="k_status" width="80">
                    <template slot-scope="{ row }">
                        <el-tag size="mini" type="success" v-if="row.k_status==2">已抵扣</el-tag>
                        <el-tag size="mini" type="info" v-else>未抵扣</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="审核状态" prop="status" width="80">
                    <template slot-scope="{ row }">
                        <el-tag size="mini" v-if="row.status==0">审核中</el-tag>
                        <el-tag size="mini" type="success" v-else-if="row.status==1">已通过</el-tag>
                        <el-tag size="mini" type="danger" v-else-if="row.status==2">已拒绝</el-tag>
                        <el-tag size="mini" type="info" v-else-if="row.status==3">已撤回</el-tag>
                        <el-tag size="mini" type="info" v-else-if="row.status==4">已撤销</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="审核时间" prop="examinetime" width="135"></el-table-column>
                <el-table-column label="操作" width="100" fixed="right" v-if="user.source_from=='fs'">
                    <template slot-scope="{row}">
                        <el-button type="text" size="mini" @click="approvalProcessBtn(row.id, row.run_id)" :disabled="!row.run_id">审批进度</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!--翻页栏-->
            <div style="margin-top: 4px;overflow: hidden;float: right;">
                <Page :total="total" :current="page" :page-size="limit" show-total @on-change="pageChange"></Page>
            </div>
        </el-col>

        <!--审核进度-->
        <el-drawer title="额外费用审批" :visible.sync="approvalVisible" size="650px" direction="rtl" :wrapperClosable="false" :before-close="closeBtn">
            <process-extra v-if="approvalVisible" :runId="runId" :id="extraId"></process-extra>
        </el-drawer>
    </section>
</template>

<script>

import {factoryList} from "@/api/produce/factory";
import processExtra from "@/view/components/flow/processExtra";
import {extraList} from "@/api/soa/extra";

export default {
    name: "soa_extra",
    components:{processExtra},
    data() {
        return {
            tableHeight: window.innerHeight - 210,
            selectIndex: 0,
            btnLoading: false,
            loading: false,
            page: 1,
            limit: 20,
            total: 0,
            data: [],
            user: {},
            nodeActions: [],

            form: {processing_code: "", factory_contract_no: "", type_no: "", supplier_id: "", k_status: "", status: ""},
            searchLoading: false,
            factoryList: [],

            approvalVisible: false,
            runId: "",
            extraId: "",

        }
    },
    created() {
        this.user = this.$store.getters.user;
        this.nodeActions = this.user.node_actions[this.$route.meta.id] ? this.user.node_actions[this.$route.meta.id] : [];
        if(this.user.source_from == 'gc'){//用户来源：工厂
            this.form.supplier_id = this.user.supplier_id;
            this.form.status = 1;
        }
    },
    watch:{
        // 监听路由参数的变化
        '$route.params.factory_contract_no': {
            immediate: true,
            handler(val) {
                if(!!val && val != this.form.factory_contract_no){
                    this.$set(this.form, 'factory_contract_no', val);
                    this.searchBtn();
                }
            }
        },
    },
    methods: {
        //搜索加工厂
        searchFactoryBtn(val){
            if(val == ""){
                return;
            }
            this.getFactoryData(val);
        },
        getFactoryData(name){
            factoryList({page: 1, limit: 200, factory_name: name, status: 0, tab: 1}).then((res) =>{
                this.factoryList = res.data.data;
            })
        },
        //搜索按钮
        searchBtn() {
            this.page = 1;
            this.getData();
        },
        //翻页
        pageChange(page) {
            this.page = page;
            this.getData();
        },
        //获取数据
        getData() {
            let param = {
                page: this.page,
                limit: this.limit
            };
            param = Object.assign(param, this.form);
            this.loading = true;
            extraList(param).then((res) => {
                this.loading = false;
                this.total = res.data.total;
                this.data = res.data.data;
            }).catch(() => {
                this.loading = false;
            });
        },
        //查看审核进度
        approvalProcessBtn(id, runId){
            this.runId = runId;
            this.extraId = id;
            this.approvalVisible = true;
        },
        closeBtn(){
            this.extraId = "";
            this.runId = "";
            this.approvalVisible = false;
        },
    },
    mounted() {
        this.getFactoryData("");
        this.searchBtn();
    }
}
</script>

<style scoped>
.el-image /deep/ .el-icon-circle-close:before{
    color: white;
}
</style>
